home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / bootany.zip / BSTRAP.ASM < prev    next >
Assembly Source File  |  1990-10-29  |  16KB  |  339 lines

  1.         page    61,132
  2.         title   Bstrap - update fixed disk bootstrap
  3.         subttl  Code
  4.         page    +
  5. Code    segment
  6.         assume  cs:Code, ds:Code, es:Code, ss:Code
  7.         org     80h
  8. parmLen db      ?
  9. parm    db      ?
  10.         org     100h
  11.         include bootany.inc
  12. Bstrap  proc    far
  13.         mov     SI,DS                           ; Get data segment
  14.         mov     ES,SI                           ; Make sure the same
  15. ;
  16. ;       Read current bootstrap record
  17. ;
  18.         mov     AX,201h                         ; read 1 sector
  19.         lea     BX,Boot                         ; buffer address
  20.         mov     CX,1                            ; cyl 0, sector 1
  21.         mov     DX,80h                          ; head 0, drive 0
  22.         int     13h                             ; read fixed disk boot
  23.         jnc     ReadOk                          ; Go on if ok
  24.         mov     bx,2                            ; write to stderr
  25.         mov     cx,Err1l                        ; length of message
  26.         lea     dx,Err1                         ; message address
  27.         mov     ah,40h                          ; write to stream
  28.         int     21h                             ; send message
  29.         jmp     Exit                            ; Exit program
  30. ReadOk:
  31. ;
  32. ;       Read in file named as parm (boot program)
  33. ;       First find the program name
  34. ;
  35.         sub     CX,CX                           ; clear register
  36.         sub     SI,SI                           ; clear register
  37.         mov     CL,parmLen                      ; Get length of parm
  38.         cmp     CL,0                            ; Better be there
  39.         jbe     NameError                       ; its not
  40.         lea     DI,parm                         ; get name address
  41.         mov     AL,' '                          ; what we will ignore
  42.         repe scasb
  43.         jcxz    NameError                       ; No parm - write msg
  44.         jmp     NameThere                       ; it is
  45. NameError:
  46.         mov     bx,2                            ; write to stderr
  47.         mov     cx,NameErrl                     ; length of message
  48.         lea     dx,NameErr                      ; message address
  49.         mov     ah,40h                          ; write to stream
  50.         int     21h                             ; send message
  51.         jmp     Exit
  52. ;
  53. ;       Found the name - Open and Read the file
  54. ;
  55. NameThere:
  56.         dec     DI                              ; Point to first byte
  57.         inc     CX                              ; Correct the count
  58.         mov     BX,CX                           ; get bytes left
  59.         mov     [BX+DI],BYTE PTR 0              ; move in terminator
  60.         mov     DX,DI                           ; Get file name start
  61.         sub     AL,AL                           ; Open for read
  62.         mov     AH,3dh                          ; Open function
  63.         int     21h                             ; Call DOS
  64.         jc      FileError
  65.         lea     DX,Boot                         ; buffer address
  66.         mov     CX,PartAddr                     ; maximum boot length
  67.         mov     BX,AX                           ; read from file
  68.         mov     AH,3fh                          ; read from stream
  69.         int     21h                             ; dos service
  70.         jnc     FileOk                          ; continue if file ok
  71. FileError:
  72.         mov     AH,3Eh                          ; Close the file
  73.         int     21h                             ; dos service
  74.         mov     BX,2                            ; write to stderr
  75.         mov     CX,Err2l                        ; length of message
  76.         lea     DX,Err2                         ; message address
  77.         mov     AH,40h                          ; write to stream
  78.         int     21h                             ; send message
  79.         jmp     Exit                            ; Exit program
  80. ;
  81. ;       The new boot program is not in our "in-memory" copy of the
  82. ;       boot sector
  83. ;
  84. FileOk:
  85. ;
  86. ;       Close the file
  87. ;
  88.         mov     AH,3Eh                          ; Close the file
  89.         int     21h                             ; dos service
  90. ;
  91. ;       Update the boot sector with User Data
  92. ;       Put out first message
  93. ;
  94.         mov     bx,2                            ; write to stderr
  95.         mov     cx,Msg1l                        ; length of message
  96.         lea     dx,Msg1                         ; message address
  97.         mov     ah,40h                          ; write to stream
  98.         int     21h                             ; send message
  99.  
  100.         mov     CX,max_partitions               ; get loop count
  101.  
  102. PartLoop:
  103. ;
  104. ;       Find out what partition this Function Key will be for
  105. ;
  106.         mov     Index,CX                        ; Save index
  107.         sub     CL,max_partitions+1             ; get negative index
  108.         neg     CL                              ; turn positive
  109.         add     CL,Numeric                      ; make displayable
  110.         mov     Q1FKey,CL                       ; move into message
  111.         mov     Q2FKey,CL                       ; move into message
  112.         mov     Q3FKey,CL                       ; move into message
  113.         mov     AL,max_partitions               ; get max value
  114.         add     AL,Numeric                      ; make displayable
  115.         mov     Q1Max,AL                        ; move into message
  116.         mov     BX,2                            ; write to stderr
  117.         mov     CX,Q1l                          ; length of message
  118.         lea     DX,Q1                           ; message address
  119.         mov     AH,40h                          ; write to stream
  120.         int     21h                             ; send message
  121.         call    GetChar                         ; Get the number
  122.         cmp     AL,'0'                          ; See if '0'
  123.         jne     NoExit                          ; If not continue
  124.         jmp     TestNumLock                     ; Exit loop
  125. NoExit:
  126.         cmp     AL,'1'                          ; See if valid value
  127.         jl      PartError                       ; No - reprompt
  128.         cmp     AL,Numeric+max_partitions       ; Check max value
  129.         ja      PartError                       ; Too big - reprompt
  130.         mov     Q2Pnum,AL                       ; Save part number
  131.         mov     Err3P,AL                        ; Save part number
  132.         sub     AL,Numeric+1                    ; Turn into index
  133.         push    AX                              ; Save for later
  134.         mov     AH,SIZE PartData                ; Get entry size
  135.         mul     AH                              ; Get offset into table
  136.         mov     Data,AX                         ; Get data address
  137.         mov     BX,AX                           ; Get data address
  138.         pop     AX                              ; Restore value
  139.         mov     AH,SIZE PartitionEntry          ; Get entry size
  140.         mul     AH                              ; Get offset into table
  141.         mov     Entry,AX                        ; Get entry address
  142.         cmp     part.partition[BX],0            ; Already in use?
  143.         je      BootTest                        ; No - use it
  144.         mov     BX,2                            ; write to stderr
  145.         mov     CX,Err3l                        ; length of message
  146.         lea     DX,Err3                         ; message address
  147.         mov     AH,40h                          ; write to stream
  148.         int     21h                             ; send message
  149. PartError:
  150.         mov     CX,Index                        ; restore index
  151.         jmp     Partloop
  152.  
  153. BootTest:
  154. ;       Check to see if the partition is marked bootable -
  155. ;       If not, see if it should be made bootable
  156. ;
  157.         mov     BX,Entry                        ; Get Entry address
  158.         cmp     partitionTable.BootIndicator[BX],0 ; Can partition boot
  159.         jne     PartBoot                        ; Yes - use it
  160.         push    AX                              ; Save for later
  161.         mov     BX,2                            ; write to stderr
  162.